import Mock from 'mockjs';

const Random = Mock.Random;

// 模拟登录接口
Mock.mock('/api/user/login', 'post', (options) => {
  const { username, password } = JSON.parse(options.body);

  if (username && password) {
    return {
      code: 200,
      message: '登录成功',
      data: {
        token: Random.string(32),
        userInfo: {
          id: Random.id(),
          username,
          nickname: Random.cname(),
          avatar: Random.image('100x100', Random.color(), '#fff', 'Avatar'),
          roles: ['user'],
          permissions: ['read', 'write']
        }
      }
    };
  } else {
    return {
      code: 400,
      message: '用户名或密码错误',
      data: null
    };
  }
});

// 模拟获取用户信息接口
Mock.mock('/api/user/info', 'get', () => {
  return {
    code: 200,
    message: '获取用户信息成功',
    data: {
      id: Random.id(),
      username: Random.name(),
      nickname: Random.cname(),
      avatar: Random.image('100x100', Random.color(), '#fff', 'Avatar'),
      email: Random.email(),
      roles: ['user'],
      permissions: ['read', 'write'],
      createTime: Random.datetime()
    }
  };
});
